<template>
	<view class="">

		<button type="primary" @click="checkIsSupportSoterAuthentication">检查支持的认证方式</button>
		<button type="primary" @click="checkIsSoterEnrolledInDeviceFingerPrint">检查是否录入指纹</button>
		<button type="primary" @click="checkIsSoterEnrolledInDeviceFaceID">检查是否录入FaceID</button>
		<button type="primary" @click="startSoterAuthenticationFingerPrint">开始指纹认证</button>
		<button type="primary" @click="startSoterAuthenticationFaceID">开始FaceID认证</button>
		<button type="primary" @click="setFullscreen">设置应用是否全屏显示</button>
		<button type="primary" @click="createMessage">创建本地消息</button>

		<button type="primary" @click="clearPush">清楚本地推送</button>
		<button type="primary" @click="Bitmap">创建Bitmap对象</button>
		<button type="primary" @click="BitmapimageAll">获取所有Bitmap图片对象</button>


		<button @click="startRecognize">开始识别</button><br />
		<button @click="alert(text);">识别内容</button>
		<image :src="src" mode=""></image>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				src: ''
			}
		},
		onShow() {
			console.log(plus.navigator.isBackground());
		},

		methods: {
			Bitmap() {
				var wc = null,
					bitmap = null,
					This = this;
				// H5 plus事件处理

				wc = plus.webview.currentWebview();
				bitmap = new plus.nativeObj.Bitmap("test", "_www/bimap/capture.png");
				// 将webview内容绘制到Bitmap对象中
				wc.draw(bitmap, function() {
					console.log('绘制图片成功');

					bitmap.save(
						"/storage/sdcard0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/doc/b.jpg", {},
						function(i) {
							console.log('保存图片成功：' + JSON.stringify(i));
							This.src = i.target
							// bitmap.load(i.target , (res)=>{
							// 	console.log(res);
							// }, err=>{
							// 	console.log(err);
							// } );
						},
						function(e) {
							console.log('保存图片失败：' + JSON.stringify(e));
						});


				}, function(e) {
					console.log('绘制图片失败：' + JSON.stringify(e));
				}, {
					check: true, // 设置为检测白屏
					clip: {
						top: '0px',
						left: '0px',
						height: '500px',
						width: '500px',
					} // 设置截屏区域
				});

			},
			BitmapimageAll() {
				var bitmaps = plus.nativeObj.Bitmap.getItems();
				for (var i = 0; i < bitmaps.length; i++) {
					console.log("Bitmap" + i + ": " + bitmaps[i].id, bitmaps[i]);
				}
			},
			checkIsSupportSoterAuthentication() {
				uni.checkIsSupportSoterAuthentication({
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					},
					complete(res) {
						console.log(res);
					}
				})
			},
			checkIsSoterEnrolledInDeviceFingerPrint() {
				uni.checkIsSoterEnrolledInDevice({
					checkAuthMode: 'fingerPrint',
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					},
					complete(res) {
						console.log(res);
					}
				})
			},
			checkIsSoterEnrolledInDeviceFaceID() {
				uni.checkIsSoterEnrolledInDevice({
					checkAuthMode: 'facial',
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					},
					complete(res) {
						console.log(res);
					}
				})
			},
			startSoterAuthenticationFingerPrint() {
				uni.startSoterAuthentication({
					requestAuthModes: ['fingerPrint'],
					challenge: '123456',
					authContent: '请用指纹解锁',
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					},
					complete(res) {
						console.log(res);
					}
				})
			},
			startSoterAuthenticationFaceID() {

				uni.startSoterAuthentication({
					requestAuthModes: ['facial'],
					challenge: '123456',
					authContent: '请用FaceID解锁',
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					},
					complete(res) {
						console.log(res);
					}
				})
			},
			setFullscreen() {
				// plus.navigator.setFullscreen(true);
			},
			createMessage() {
				let ps = plus.push.createMessage('selfsummer', {
					name: 17
				}, {
					title: '测试title'
				});

				plus.push.addEventListener('receive', function(e) {
					alert('PushReceiveCallback: ' + JSON.stringify(e));
				}, false);
				plus.push.addEventListener('click', function(e) {
					alert('PushClickCallback: ' + JSON.stringify(e));
				}, false);
			},
			clearPush() {
				// 清楚所有
				// plus.push.clear()

				// plus.push.getAllMessage()

				plus.share.sendWithSystem('********', (res) => {
					console.log(res, 'res');
				}, (err) => {
					console.log(err, 'err');
				});
			},
			startRecognize() {
				var options = {};
				options.engine = 'iFly';
				let text = "";
				console.log("开始语音识别：");
				plus.speech.startRecognize(options, function(s) {
					text += s;
					console.log(text);
				}, function(e) {
					console.log("语音识别失败：" + e.message);
				});
			}
		}
	}
</script>

<style>
	button {
		width: 200px;
		margin: 20px auto;
	}
</style>
